package com.model.math;

public class Point3D {
    public double x, y, z;

    public Point3D(double x, double y, double z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    /**
     * 计算点集的中心点
     */
    public static Point3D computeCenter(Point3D[] points) {
        if (points == null || points.length == 0) {
            return new Point3D(0, 0, 0);
        }

        double sumX = 0, sumY = 0, sumZ = 0;
        for (Point3D point : points) {
            sumX += point.x;
            sumY += point.y;
            sumZ += point.z;
        }

        int n = points.length;
        return new Point3D(sumX / n, sumY / n, sumZ / n);
    }

    /**
     * 计算到另一个点的距离
     */
    public double distanceTo(Point3D other) {
        double dx = this.x - other.x;
        double dy = this.y - other.y;
        double dz = this.z - other.z;
        return Math.sqrt(dx * dx + dy * dy + dz * dz);
    }

    /**
     * 创建点的副本
     */
    public Point3D clone() {
        return new Point3D(x, y, z);
    }

    @Override
    public String toString() {
        return String.format("Point3D(%.2f, %.2f, %.2f)", x, y, z);
    }
} 